package cn.lizemin.flowable.controller;

import cn.lizemin.flowable.common.RespBean;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author lzm
 * @Date 2024/7/15
 * @description
 */
@RequestMapping("/flow")
@RestController
public class FlowController {

    @Autowired
    RepositoryService repositoryService;

    /**
     * 手动部署流程
     */
    @GetMapping("/deployProcess")
    public RespBean deployProcess(MultipartFile file) throws IOException {
        DeploymentBuilder builder = repositoryService.createDeployment()
                .name("lzm工作流") // act_re_deployment表中的name属性
                .category("请假流程")  // act_re_deployment表中的category属性
                .key("自定义工作流key") // act_re_deployment表中的key属性
                .addInputStream(file.getName(), file.getInputStream());
        Deployment deploy = builder.deploy();
        return RespBean.success(deploy.getId()).message("部署成功");
    }




}
